package ntd.util.config.common.enums.msg;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import ntd.util.config.common.enums.BaseEnumInterface;
import ntd.util.config.common.enums.EnumPlatformType;
import ntd.util.frame.msg.MsgHandle;
import ntd.util.frame.msg.service.handle.aliyun.AliyunMsgHandle;
import ntd.util.frame.msg.service.handle.jpush.push.JPushMsgHandle;
import ntd.util.frame.msg.service.handle.jpush.sms.JPushSmsHandle;

import java.util.List;

@AllArgsConstructor
public enum EnumMsgHandle implements BaseEnumInterface {

    ALIYUN_MSG(EnumPlatformType.ALIYUN, EnumMsgType.SMS, new AliyunMsgHandle()),
    JPUSH_PUSH(EnumPlatformType.JPUSH, EnumMsgType.PUSH, new JPushMsgHandle()),
    JPUSH_SMS(EnumPlatformType.JPUSH, EnumMsgType.SMS, new JPushSmsHandle()),
    ;

    @Getter
    private final EnumPlatformType enumPlatformType;
    @Getter
    private final EnumMsgType enumMsgType;
    @Getter
    private final MsgHandle msgHandle;

    @Override
    public String getValue() {
        return this.name();
    }

    /**
     * 根据类型获取执行handle枚举
     * @param enumMsgType
     * @return
     */
    public static List<EnumMsgHandle> listByMsgType(EnumMsgType enumMsgType) {
        return CollUtil.filter(ListUtil.toList(EnumMsgHandle.values()), enumMsgHandle -> enumMsgType.equals(enumMsgHandle.getEnumMsgType()));
    }

    @Override
    public String getName() {
        return this.name();
    }
}
